package cn.edu.ujn.lab3.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.StringUtils;

import cn.edu.ujn.lab3.dao.Project;
import cn.edu.ujn.lab3.dao.ProjectMapper;
import cn.edu.ujn.lab3.utils.Page;
@Service("projectService")
@Transactional
public class ProjectServiceImpl implements IProjectService {

	@Autowired
	private ProjectMapper projectdao;
	
	@Override
	public int deleteByPrimaryKey(Integer projectId) {
		// TODO Auto-generated method stub
		return projectdao.deleteByPrimaryKey(projectId);
	}

	@Override
	public int insert(Project row) {
		// TODO Auto-generated method stub
		return projectdao.insert(row);
	}

	@Override
	public int insertSelective(Project row) {
		// TODO Auto-generated method stub
		return projectdao.insertSelective(row);
	}

	@Override
	public Project selectByPrimaryKey(Integer projectId) {
		// TODO Auto-generated method stub
		return projectdao.selectByPrimaryKey(projectId);
	}

	@Override
	public int selectProjectCount() {
		// TODO Auto-generated method stub
		return projectdao.selectProjectCount();
	}

	@Override
	public List<Project> selectProjectList(Project row) {
		// TODO Auto-generated method stub
		return projectdao.selectProjectList(row);
	}

	@Override
	public int updateByPrimaryKeySelective(Project row) {
		// TODO Auto-generated method stub
		return projectdao.updateByPrimaryKeySelective(row);
	}

	@Override
	public int updateByPrimaryKey(Project row) {
		// TODO Auto-generated method stub
		return projectdao.updateByPrimaryKey(row);
	}

	@Override
	public Page<Project> findProjectList(Integer page, Integer rows, Integer prodect_id, Integer employee_id,
			Integer project_commission, String project_version, Integer project_state) {
		// TODO Auto-generated method stub
		Project project = new Project();
		project.setProject_id(prodect_id);
		project.setemployee_id(employee_id);
		project.setProject_commission(project_commission);
		project.setProject_state(project_state);
		if(!StringUtils.isNullOrEmpty(project_version)) {
			project.setProject_version(project_version);
		}
		project.setStart((page-1) * rows);
		project.setRows(rows);
		List<Project> projects = projectdao.selectProjectList(project);
		int count = projectdao.selectProjectCount();
		Page<Project> result = new Page<Project>();
		result.setPage(page);
		result.setRows(projects);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}

	@Override
	public List<Project> selectProjectsWithUser(Integer id) {
		// TODO Auto-generated method stub
		List<Project> list = projectdao.selectProjectsWithUser(id);
		return list;
	}

}
